<template>
  <div class="commentItem">
    <!-- 添加上一级评论结构 -->
    <!-- v-if：到底要不要再继续递归，只有parent才需要递归
      :parent：将当前评论的parent属性作为参数传递
       -->
    <!-- @replay="replayItem" 递归组件内的回复 -->
    <hmcommentitem
      v-if="parent.parent"
      :parent="parent.parent"
      @replay="replayItem"
    ></hmcommentitem>

    <div class="top">
      <div class="left">
        <span>{{ parent.user.nickname }}</span> &nbsp;&nbsp;&nbsp;
        <span>2分钟前</span>
      </div>
      <span @click="replayItem(parent)">回复</span>
    </div>
    <div class="bottom">{{ parent.content }}</div>
  </div>
</template>

<script>
export default {
  // 这个属性的值就可以当成组件来使用
  name: "hmcommentitem",
  props: {
    parent: {
      type: Object,
    },
  },
  methods: {
    replayItem(v) {
      this.$emit("replay", v);
    },
  },
};
</script>

<style lang="less" scoped>
.commentItem {
  border: 1px solid #ccc;
  padding: 5px;
  margin-top: 10px;
  .top {
    font-size: 12px;
    color: #aaa;
    display: flex;
    justify-content: space-between;
  }
  .bottom {
    font-size: 13px;
    line-height: 40px;
  }
}
</style>